

package com.mt.restaurant.controller.staff;

import com.mt.common.core.web.JsonResult;
import io.lettuce.core.dynamic.annotation.Param;
import org.springframework.security.access.prepost.PreAuthorize;
import com.mt.common.core.annotation.ApiPageParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.mt.common.core.web.base.PageDTO;
import com.mt.common.core.web.base.PageResultDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;



import com.mt.restaurant.dto.staff.StaffEditDto;
import com.mt.restaurant.entity.staff.Staff;
import com.mt.restaurant.service.staff.StaffService;
										

@Api(tags = "员工")
@RestController
@RequestMapping("/api/restaurant/staff/Staff")
@CrossOrigin(allowCredentials = "true")
public class StaffController {
private static Logger logger = LoggerFactory.getLogger(StaffController.class);



																																	@Autowired private StaffService staffService;
	
	/**
	* 根据分页参数查询员工集合
	*
	* @param pageDTO 分页条件
	*/
//	@PreAuthorize("hasAuthority('restaurant:staff:Staff:view')")
	@ApiOperation("分页查询员工")
	@ApiPageParam
	@PostMapping("/findStaffs")
	public PageResultDTO findStaffs(@RequestBody PageDTO pageDTO){
		return this.staffService.findStaffs(pageDTO);
	}

	/**
	* 根据ID查询指定的员工
	*
	* @param staffId Id
	*/
	@PreAuthorize("hasAuthority('restaurant:staff:Staff:view')")
	@ApiOperation("根据id查询员工")
	@ApiPageParam
	@PostMapping("/findStaff")
	public Staff findStaff(@RequestParam Long staffId){
		return this.staffService.findStaff(staffId);
	}

	/**
	* 根据ID查询指定的员工(包含外键名称)
	*
	* @param staffId Id
	*/
	@PreAuthorize("hasAuthority('restaurant:staff:Staff:view')")
	@ApiOperation("根据ID查询指定的员工(包含外键名称)")
	@PostMapping("/findStaffForView")
	public Staff findStaffForView(@RequestParam Long staffId){
		return this.staffService.findStaffWithForeignName(staffId);
	}

	/**
	* 根据ID查询指定的员工(包含员工和外键名称)
	*
	* @param staffId Id
	*/
	@PreAuthorize("hasAuthority('restaurant:staff:Staff:view')")
	@ApiOperation("根据ID查询指定的员工(包含员工和外键名称)")
	@PostMapping("/findStaffForEdit")
	public StaffEditDto findStaffForEdit(@RequestParam Long staffId){
				StaffEditDto staffEditDto = new StaffEditDto();
		staffEditDto.setStaff(this.staffService.findStaffWithForeignName(staffId));

		this.prepareStaffEditDto(staffEditDto);

		return staffEditDto;
	}

	/**
	* 根据ID查询指定的员工(只提取ID 和 Name)
	*
	* @param staffId Id
	*/
	@PreAuthorize("hasAuthority('restaurant:staff:Staff:view')")
	@ApiOperation("根据ID查询指定的员工(只提取ID 和 Name)")
	@PostMapping("/findStaffsWithIdNameById")
	public Staff findStaffsWithIdNameById(@RequestParam Long staffId){
	return this.staffService.findStaffsWithIdNameById(staffId);
	}

	/**
	* 根据名称查询员工集合(只提取ID 和 Name)
	*
	* @param staffName 名称
	*/
	@PreAuthorize("hasAuthority('restaurant:staff:Staff:view')")
	@ApiOperation("根据名称查询员工集合(只提取ID 和 Name)")
	@PostMapping("/findStaffsWithIdNameByName")
	public List<Staff> findStaffsWithIdNameByName(@RequestParam String staffName){
	return this.staffService.findStaffsWithIdNameByName(staffName);
	}


	/**
	* 创建新的员工
	*
	*/
	@PreAuthorize("hasAuthority('restaurant:staff:Staff:add')")
	@ApiOperation("创建新的员工")
	@PostMapping("/createStaff")
	public StaffEditDto createStaff(){
				StaffEditDto staffEditDto = new StaffEditDto();
		staffEditDto.setStaff(new Staff());

		this.prepareStaffEditDto(staffEditDto);
		return staffEditDto;
	}

	private void prepareStaffEditDto(StaffEditDto staffEditDto){
																																}

	/**
	* 新增保存员工
	*
	* @param staff 实体对象
	*/
	@PreAuthorize("hasAuthority('restaurant:staff:Staff:add')")
	@ApiOperation("新增保存员工")
	@PostMapping("/saveStaff")
	public Staff saveStaff(@RequestBody Staff staff){
		return this.staffService.saveStaff(staff);
	}

	/**
	* 修改保存员工
	*
	* @param staff 实体对象
	*/
	@PreAuthorize("hasAuthority('restaurant:staff:Staff:update')")
	@ApiOperation("修改保存员工")
	@PostMapping("/updateStaff")
	public Staff updateStaff(@RequestBody Staff staff){
		return this.staffService.updateStaff(staff);
	}

	/**
	* 根据ID删除员工
	*
	* @param staffId ID
	*/
	@PreAuthorize("hasAuthority('restaurant:staff:Staff:remove')")
	@ApiOperation("根据ID删除员工")
	@PostMapping("/deleteStaff")
	public void deleteStaff(@RequestParam Long staffId){
		this.staffService.deleteStaff(staffId);
	}

	@PreAuthorize("hasAuthority('restaurant:staff:Staff:remove')")
	@ApiOperation("根据员工账号生成userId")
	@PostMapping("/generateUser")
	public JsonResult generateUser(@RequestBody List<Staff> staffs){
		return this.staffService.generateUser(staffs);
	}


}

